package com.yeraphael.aop;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
public class DemoAspect {

    @Pointcut("execution(* com.yeraphael.service.impl.DeptServiceImpl.*(..))")
    public void pt(){};

    @Pointcut("@annotation(com.yeraphael.annotation.Log)")
    public void pt2(){};

    @Around("pt2()")
    public Object recordTime(ProceedingJoinPoint joinPoint) throws Throwable {
        long startTime = System.currentTimeMillis();

        Object result = joinPoint.proceed();

        long endTime = System.currentTimeMillis();
        log.info("执行时间：{}",  endTime - startTime);

        return result;
    }

}
